import React, { Component } from "react";import { connect } from "dva";import { routerRedux } from "dva/router";import { Card, Button, Icon, Input, message, Tag, Form, DatePicker, Select, Table, Pagination } from "antd";import MarkdownEditor from "@/utils/vditorContent";import { formatMessage } from 'umi-plugin-react/locale';import { agreementRecords } from "@/services/platformManagement";import moment from "moment";

class SignDetails extends Component {
	constructor(props) {
		super(props);
		this.state = {
			current:1,
      size:10,
      total:0,
      loading:false,
      list:[],
      pathname:"",
		};
	}

	componentDidMount() {
    const { location:{pathname} } = this.props;
    this.setState({pathname},() => {
      this.getList()
    })
		
	}

  getList = () => {
    this.setState({
      loading:true
    },async () => {
      const { pathname,current,size } = this.state;
      const { form:{getFieldsValue},location:{query} } = this.props;
      let obj = {
        current,
        size,
        startTime : getFieldsValue().time && getFieldsValue().time[0] ? moment(getFieldsValue().time[0]).format("YYYY-MM-DD HH:mm:ss") : '',
        endTime : getFieldsValue().time && getFieldsValue().time[1] ? moment(getFieldsValue().time[1]).format("YYYY-MM-DD HH:mm:ss") : '',
        param:getFieldsValue().param,
        id:query.id
      }
      const res = await agreementRecords(obj)
      this.setState({loading:false,list:res.records,total:res.total})
    })
  }

  doSearch = (current,size) => {
    this.setState({current,size},() => {
      this.getList()
    })
  }

  toBack = () => {
    const { location:{query},history } = this.props;
    history.push({ pathname: query.pathname })
  }

	render() {
		const { current,size,total,list,loading } = this.state;
    const { form:{getFieldDecorator} } = this.props;
    const columns = [{title: formatMessage({ id: 'platformManagement.agreementInfo.userId', defaultMessage: '用户ID' }),dataIndex:"userId",width:150},{title: formatMessage({ id: 'platformManagement.agreementInfo.userName', defaultMessage: '用户名称' }),dataIndex:"name",width:150},{title: formatMessage({ id: 'platformManagement.agreementInfo.account', defaultMessage: '账号' }),dataIndex:"username",width:200,},{title: formatMessage({ id: 'platformManagement.agreementInfo.organization', defaultMessage: '所属公司/组织' }),dataIndex:"deptName",width:150},{title: formatMessage({ id: 'platformManagement.agreementInfo.firstSignTime', defaultMessage: '首次签订时间' }),dataIndex:"createTime",width:200,render:time => {return time ? moment(time).format("YYYY-MM-DD HH:mm:ss") : ''}}]

		return (
      <div style={{height:"100%",padding:24,background:'#ffffff',overflowY:"auto"}}>
				<div style={{display:"flex",justifyContent:"space-between",alignItems:"center",marginBottom:24}}>
          <Form layout="inline">
            <Form.Item>
              {
                getFieldDecorator("time")(
                  <DatePicker.RangePicker style={{width:220}} />
                )
              }
            </Form.Item>
            <Form.Item>
              {
                getFieldDecorator("param",{initialValue:''})(
                  <Input.Search placeholder={formatMessage({ id: 'platformManagement.agreementInfo.searchUser', defaultMessage: '查询用户名称、ID、手机号' })} onSearch={() => this.doSearch(1,size)} style={{width:250}} />
                )
              }
            </Form.Item>
            <Form.Item>
              <Button type="primary" onClick={() => this.doSearch(1,size)}>{formatMessage({ id: 'platformManagement.agreementInfo.search', defaultMessage: '查询' })}</Button>
            </Form.Item>
          </Form>
          <Button type="primary" onClick={this.toBack}>{formatMessage({ id: 'platformManagement.agreementInfo.return', defaultMessage: '返回' })}</Button>
        </div>
        <Table 
          columns={columns}
          dataSource={list}
          loading={loading}
          rowKey={'id'}
          pagination={false}
          scroll={{x:'auto'}}
        />
        {total > 10 ? (
          <Pagination
            style={{ textAlign: 'right', marginTop: 16 }}
            total={total}
            current={current}
            pageSize={size}
            showQuickJumper={true}
            showSizeChanger={true}
            onChange={this.doSearch}
            onShowSizeChange={this.doSearch}
          />
        ) : null}
      </div>
		);
	}
}

export default Form.create()(SignDetails)
